package com.ruoyi.classroom.course.controller;


import com.ruoyi.classroom.course.domain.MyTeacherCourse;
import com.ruoyi.classroom.course.service.IMyTeacherCourseService;
import com.ruoyi.classroom.user.domain.User;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 我的授课Controller
 * 
 * @author lgm
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/MyTeacherCourse/MyTeacherCourse")
public class MyTeacherCourseController extends BaseController
{
    @Autowired
    private IMyTeacherCourseService myTeacherCourseService;

    /**
     * 查询我的授课列表
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:list")
    @GetMapping("/list")
    public TableDataInfo list(MyTeacherCourse myTeacherCourse)
    {
        startPage();
        List<MyTeacherCourse> list = myTeacherCourseService.selectMyTeacherCourseList(myTeacherCourse);
        return getDataTable(list);
    }
    /**
     * 查询出选课的学生selectStudentCourseList
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:list")
    @GetMapping("/selectStudentCourseList")
    public TableDataInfo selectStudentCourseList(MyTeacherCourse myTeacherCourse)
    {

        startPage();
        List<User> list = myTeacherCourseService.selectStudentCourseList(myTeacherCourse);
        return getDataTable(list);
    }

    /**
     * 导出我的授课列表
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:export")
    @Log(title = "我的授课", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyTeacherCourse myTeacherCourse)
    {
        List<MyTeacherCourse> list = myTeacherCourseService.selectMyTeacherCourseList(myTeacherCourse);
        ExcelUtil<MyTeacherCourse> util = new ExcelUtil<MyTeacherCourse>(MyTeacherCourse.class);
        util.exportExcel(response, list, "我的授课数据");
    }

    /**
     * 获取我的授课详细信息
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myTeacherCourseService.selectMyTeacherCourseById(id));
    }

    /**
     * 新增我的授课
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:add")
    @Log(title = "我的授课", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyTeacherCourse myTeacherCourse)
    {
        return toAjax(myTeacherCourseService.insertMyTeacherCourse(myTeacherCourse));
    }

    /**
     * 修改我的授课
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:edit")
    @Log(title = "我的授课", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyTeacherCourse myTeacherCourse)
    {
        return toAjax(myTeacherCourseService.updateMyTeacherCourse(myTeacherCourse));
    }

    /**
     * 删除我的授课
     */
    @RequiresPermissions("MyTeacherCourse:MyTeacherCourse:remove")
    @Log(title = "我的授课", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myTeacherCourseService.deleteMyTeacherCourseByIds(ids));
    }
}
